﻿#include<iostream>
using namespace std;

const int N = 10010;
int n, a[N], s[N];
int main()
{
	cin >> n;								
	for (int i = 0; i < n; i++)cin >> a[i]; //1 2 2 3 5
	int res = 0;
	for (int i = 0, j = 0; i < n; i++)	
	{
		s[a[i]]++;			//i=0,j=0; s[a[0]]++; a[0]=1; s[1]++; 
							//i=1,j=0; s[a[1]]++; a[1]=2; s[2]++;
							//i=2,j=0; s[a[2]]++; a[2]=2; s[2]++;
							//i=3,j=1; s[a[3]]++; a[3]=3; s[3]++;
							//i=4,j=1; s[a[4]]++; a[4]=5; s[5]++;
		while (s[a[i]] > 1)			//s[1] = 1 !> 1
		{							//s[2] = 1 !> 1
									//s[2] = 2 >  1
									//s[3] = 1 !> 1
									//s[5] = 1 !> 1
			s[a[j]]--;//a[j]=a[0]=1 s[1]--; 
			j++;
		}
		res = max(res, i - j + 1);  //i=0,j=0 res = (0,0-0+1) = 1;
	}							    //i=1,j=0 res = (1,1-0+1) = 2;
								    //i=2,j=1 res = (2,2-1+1) = 2;
									//i=3,j=1 res = (2,3-1+1) = 2;
									//i=4,j=1 res = (2,4-1+1) = 3;
	cout << res << endl;
	system("pause");
	return 0;
};